var t = require("../../utils/http.js"),
  a = require("../../utils/api.js"),
  i = require("../../utils/language/switchLanguage.js");
Page({
  data: {
    startX: 0,
    delIndex: -1,
    list: [],
    editList: "",
    array: ["身份证", "护照"],
    eArray: ["ID Card", "Passport"],
    index: "",
    name: "",
    idCard: "",
  },
  onLoad: function (t) {
    this.initLanguage(), this.getConcatList();
  },
  initLanguage: function () {
    var t = i.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: t, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: t["常用联系人"] });
  },
  getConcatList: function () {
    var a = this;
    t.getConcatList().then(function (t) {
      a.setData({ list: t.data });
    });
  },
  uploadImg: function () {
    wx.chooseMedia({
      count: 1,
      mediaType: ["image"],
      sourceType: ["album", "camera"],
      camera: "back",
      success: function (t) {},
    });
  },
  RemoveConcat: function (a) {
    var i = this,
      e = a.currentTarget.dataset.idx,
      s = this.data.list[e].id;
    t.RemoveConcat(s).then(function (t) {
      var a = i.data.list;
      a.splice(e, 1), i.setData({ list: a });
    });
  },
  AddConcat: function () {
    var i = this;
    if ("" != this.data.name)
      if ("" != this.data.idCard)
        if ("" != this.data.index) {
          var e = {
            customerName: this.data.name,
            customerIdCard: this.data.idCard,
            customerIdCardType: 0 == this.data.index ? 0 : 4,
          };
          t.AddConcat(e).then(function (t) {
            a.showMsg(i.data._t["添加成功"]),
              i.setData({ isShow: !1, index: "", name: "", idCard: "" }),
              i.getConcatList();
          });
        } else a.showMsg(this.data._t["请选择证件类型"]);
      else a.showMsg(this.data._t["证件号码不能为空"]);
    else a.showMsg(this.data._t["姓名不能为空"]);
  },
  Edit: function (t) {
    var a = t.currentTarget.dataset.idx;
    this.setData({
      editList: this.data.list[a],
      isShow: !0,
      name: this.data.list[a].customerName,
      idCard: this.data.list[a].customerIdCard,
      index: 0 == this.data.list[a].customerIdCardType ? "0" : 1,
    });
  },
  EditConcat: function (i) {
    var e = this;
    if ("" != this.data.name)
      if ("" != this.data.idCard)
        if ("" != this.data.index) {
          var s = {
            id: this.data.editList.id,
            customerName: this.data.name,
            customerIdCard: this.data.idCard,
            customerIdCardType: 0 == this.data.index ? 0 : 4,
          };
          this.setData({
            editList: [],
            isShow: !1,
            name: "",
            idCard: "",
            index: "",
          }),
            t.UpdateConcat(s).then(function (t) {
              a.showMsg(e.data._t["修改成功"]), e.getConcatList();
            });
        } else a.showMsg(this.data._t["请选择证件类型"]);
      else a.showMsg(this.data._t["证件号码不能为空"]);
    else a.showMsg(this.data._t["姓名不能为空"]);
  },
  touchstart: function (t) {
    this.setData({ startX: t.changedTouches[0].clientX, delIndex: -1 });
  },
  touchmove: function (t) {
    var a = t.currentTarget.dataset.index,
      i = this.data.startX,
      e = t.changedTouches[0].clientX,
      s = this.data.delIndex;
    (s = e > i ? -1 : a), this.setData({ delIndex: s });
  },
  AddContact: function (t) {
    this.setData({ isShow: !0 });
  },
  Cancel: function () {
    this.setData({ isShow: !1, editList: [], name: "", idCard: "", index: "" });
  },
  getName: function (t) {
    this.setData({ name: t.detail.value });
  },
  getIDcard: function (t) {
    this.setData({ idCard: t.detail.value });
  },
  bindPickerChange: function (t) {
    this.setData({ index: t.detail.value });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
